<?php
/*
MySQL Class door Jasper van der Meulen (c) 2010
Typenummer: mysql280320101500
*/
class sql {
	protected $debug = "1";
	function debug()
	{	
		$debug = "
		<style type='text/css' />
		#debug{
		width: 300px; height: auto;
		background-color:  #D8D8D8;
		position:absolute;top:1px;
		margin-left:80%;
		border-style:solid;
		border-width:2px;
		border-color:#686868;
		}
		</style>
		<html>
		<div id='debug'>
		<b>Uitgevoerde MYSQL query's:</b><br />".$this->debugdata."mysql_class.php</div><html>";
		return $debug;
	}

	function verbinden($server,$naam,$wachtwoord,$databasenaam) {
		$db = mysql_connect($server,$naam,$wachtwoord);
		mysql_select_db($databasenaam,$db);
	}
	function select($tabel,$wat,$waar,$sorteren,$limiet)
	{
		$query = "SELECT ".$wat." FROM ".$tabel."";
		if (!empty($waar))
		{
			
			$query .= " where ".$waar."";
		} 
		if (!empty($sorteren))
		{
			$sorteren = explode("/", $sorteren);
			if ($sorteren['0'] == "+")
			{
				$query .= " ORDER BY ".$sorteren['1']." ASC";
			}else{
				$query .= " ORDER BY ".$sorteren['1']." DESC";
			}
		}
		if (!empty($limiet))
		{
			$query .= " LIMIT ".$limiet."";
		}
		if ($this->debug == "1")
		{
			$this->debugdata .= "".$query."<br />";
		}

		$query = mysql_query($query);
		return $query;
	}
	function lees($query,$wat)
	{
		if ($wat == "array")
		{
			$query = mysql_fetch_array($query);
			return $query;
		}else{
			$query = mysql_fetch_array($query);
			return $query['0'];
		}
	}	
	function update($tabel,$wat,$waar)
	{
		$query = "UPDATE ".$tabel." SET ".$wat." WHERE ".$waar."";
		mysql_query($query);
		if ($this->debug == "1")
		{
			$this->debugdata .= "".$query."<br />";
		}
	}
	function verwijderen($tabel,$waar)
	{
		$query = "DELETE FROM $tabel WHERE ".$waar."";
		if ($this->debug == "1")
		{
			$this->debugdata .= "".$query."<br />";
		}
		mysql_query($query);
	}
	function toevoegen($tabel,$wat)
	{
		$query = "INSERT INTO ".$tabel." SET ".$wat."";
		if ($this->debug == "1")
		{
			$this->debugdata .= "".$query."<br />";
		}
		mysql_query($query);
	}
	function tellen($tellen)
	{
		return mysql_num_rows($tellen);
	}
	function post($wat)
	{
		return mysql_real_escape_string($wat);
	}
}
?>
